/**
 * This file is Copyright © 2008 Software Craftsmen Limited. All Rights Reserved.
 */
package com.softwarecraftsmen.collections.tuples;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Matcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;

public class HasHashCodeEqualTo<T> extends BaseMatcher<T>
{
	private final T hasMatchingHashCode;

	public HasHashCodeEqualTo(final T hasMatchingHashCode)
	{
		this.hasMatchingHashCode = hasMatchingHashCode;
	}

	public boolean matches(final Object item)
	{
		return item != null && item.hashCode() == hasMatchingHashCode.hashCode();
	}

	public void describeTo(final Description description)
	{
		description
		.appendText("asHashCode(")
		.appendText(")");
	}

	@Factory
	public static <T> Matcher<T> hasHashCodeEqualTo(final T hasMatchingHashCode)
	{
		return new HasHashCodeEqualTo<T>(hasMatchingHashCode);
	}
}
